package com.example.managemyself.ui.tasks;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.adapter.FragmentStateAdapter;

/**
 * 任务页面ViewPager适配器，用于管理学习、健康、杂务三个子页面
 */
public class TaskPagerAdapter extends FragmentStateAdapter {
    
    private final int tabCount;
    
    public TaskPagerAdapter(@NonNull Fragment fragment, int tabCount) {
        super(fragment);
        this.tabCount = tabCount;
    }
    
    @NonNull
    @Override
    public Fragment createFragment(int position) {
        // 根据位置创建对应的Fragment，使用Bundle传递参数
        String taskType;
        switch (position) {
            case 0:
                taskType = "学习";
                break;
            case 1:
                taskType = "健康";
                break;
            case 2:
                taskType = "杂务";
                break;
            default:
                taskType = "学习";
                break;
        }
        
        // 使用静态工厂方法创建Fragment，确保参数正确传递
        return TaskListFragment.newInstance(taskType);
    }
    
    @Override
    public int getItemCount() {
        return tabCount;
    }
} 